package com.baize.mq.cust;


import com.baize.mq.param.RabbitParam;
import com.baize.mq.pojo.RabbitRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class Customer {
    // 监听队列
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "china.news"),
            exchange = @Exchange(name = "news.exchange", type = ExchangeTypes.TOPIC),
            // 绑定的key
            key = "china.news"
    ))
    public void chineNews(RabbitRequest msg) {
        log.info("中国接收到新闻：{}", msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "japan.news"),
            exchange = @Exchange(name = "news.exchange", type = ExchangeTypes.TOPIC),
            key = "japan.news"
    ))
    public void japanNews(RabbitRequest msg) {
        log.info("日本接收到新闻:{}", msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "england.news"),
            exchange = @Exchange(name = "news.exchange", type = ExchangeTypes.TOPIC),
            key = "england.news"
    ))
    public void englandNews(RabbitRequest msg) {
        log.info("英国接收到新闻：{}", msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "all.news"),
            exchange = @Exchange(name = "news.exchange", type = ExchangeTypes.TOPIC),
            key = "#.news"
    ))
    public void allNews(RabbitRequest msg) {
        log.info("所有国家接收到新闻：{}", msg);
    }
}
